<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8"/>
    <title>App配置变更</title>
    <link rel="shortcut icon" th:href="@{/static/favicon.ico}"/>
    <link rel="bookmark" th:href="@{/static/favicon.ico}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/css/bootstrap.css}"/>
</head>
<body class="container">
<div class="with:80%" style="margin-top: 100px;">
    <table class="table table-hover">
        <thead>
        <tr>
            <th>#</th>
            <th>dict_name</th>
            <th>dict_key</th>
            <th>dict_value</th>
            <th>dict_type</th>
            <th>dict_desc</th>
            <th>status</th>
            <th>delete_flag</th>
            <th>operator</th>
            <th>create_time</th>
            <th>update_time</th>
            <th>delete_time</th>
            <th>operation</th>
        </tr>
        </thead>
        <tbody>
        <tr  th:each="dict,thisdict : ${dicts}">
            <th scope="row" th:text="${thisdict.count}"></th>
            <td th:text="${dict.dict_name}"></td>
            <td th:text="${dict.dict_key}"></td>
            <td th:text="${dict.dict_value}"></td>
            <td th:text="${dict.dict_type}"></td>
            <td th:text="${dict.dict_desc}"></td>
            <td th:text="${dict.status}"></td>
            <td th:text="${dict.delete_flag}"></td>
            <td th:text="${dict.operator}"></td>
            <td th:text="${#dates.format(dict.create_time, 'yyyy-MM-dd HH:mm:ss')}"></td>
            <td th:text="${#dates.format(dict.update_time, 'yyyy-MM-dd HH:mm:ss')}"></td>
            <td th:text="${#dates.format(dict.delete_time, 'yyyy-MM-dd HH:mm:ss')}"></td>
            <td><button class="btn btn-danger btn-xs" data-toggle="modal" data-target="#settingModal" th:onclick="'javascript:goToUpdate(\''+${dict.id}+'\');'">修改</button></td>
        </tr>
        </tbody>
    </table>
    <!-- Modal -->
    <div class="modal fade" id="settingModal" tabindex="-1" role="dialog" aria-labelledby="settingModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="settingModalLabel">配置变更</h4>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal" href="#">
                        <input type="hidden" class="form-control" id="dictid">
                        <div class="form-group">
                            <label for="updateValue" class="col-sm-2 control-label">updateValue</label>
                            <div class="col-sm-10">
                                <input type="email" class="form-control" id="updateValue" placeholder="updateValue">
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary" id="confirm">确定</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" th:src="@{/js/jquery.min.js}"></script>
<script type="text/javascript" th:src="@{/js/bootstrap.min.js}"></script>
<script type="text/javascript">
    $(function () {
        function centerModals() {
            $('#settingModal').each(function (i) {
                var $clone = $(this).clone().css('display', 'block').appendTo('body');
                var top = Math.round(($clone.height() - $clone.find('.modal-content').height()) / 2);
                top = top > 0 ? top : 0;
                $clone.remove();
                $(this).find('.modal-content').css("margin-top", top);
            });
        };

        $('#settingModal').on('show.bs.modal', centerModals);
    });
    //模态框赋初始值
    function goToUpdate(id){
        $('#dictid').val(id);
    };

    //修改方法
    $('#confirm').click(function () {
        var dictid = $('#dictid').val();
        var updateValue = $('#updateValue').val();
        if(updateValue != null && updateValue != ''){
            $.ajax({
                url:"/lovin/config/refresh",
                type: "POST",
                data: {
                    dictid: dictid,
                    updateValue: updateValue
                },
                dataType: "json",
                success: function(data){
                    console.log(data);
                    if(data.code == 0){
                        $('#settingModal').modal('hide');
                        window.location.reload();
                    }else {
                        alert(data.msg);
                    }
                },
                error: function(xhr, type, errorThrown) {
                    //异常处理；
                    console.info("URL_ALARMCOUNTTYPELEVEL error:" + type);
                }
            });
        }else{
            alert("更新的配置不能为空")
        }


    });
</script>
</body>
</html>
